package structuralPatterns.composite;

import java.util.ArrayList;
import java.util.List;

public class Composite extends Component{
    List<Component> list = new ArrayList<Component>();

    public Composite(String name){
        this.name = name;
    }
    public void add(Component c){
        list.add(c);
    }

    public void remove(Component c){
        list.remove(c);
    }

    public void eachChild(){
        System.out.println(name+"执行了");
        for (Component c:list) {
            c.eachChild();
        }
    }
}
